package com.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/5 10:33
 * @Version 1.0
 **/
@Controller
@RequestMapping("test")
public class TestController {
    @RequestMapping("testVoid")
    public void testVoid(HttpServletRequest request, HttpServletResponse response)throws Exception {
        request.setAttribute("arg","testVoid");
        request.getRequestDispatcher("/WEB-INF/pages/test.jsp").forward(request, response);
    }

    @RequestMapping("hello")
    public String sayHello(Map<String,Object> map){
        map.put("arg","铁蛋");
        map.put("sage",19);
        return "test";
    }
    @RequestMapping("index")
    public String index(){
        System.out.println(111);
        return "test";
    }

    @RequestMapping("testModelAndView")
    public ModelAndView testModelAndView(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("arg","eric");
        modelAndView.setViewName("test");
        return modelAndView;
    }

    @RequestMapping("testForward")
    public String testForward(){
//        /WEB-INF/pages/test.jsp
        return "forward:/check.html";
    }

    @RequestMapping("testRedirect")
    public String testRedirect() {
        return "redirect:/test/index";
    }


}
